package d0330;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class HaHa {
    public static void main(String[] args) {
        ServerSocket serverSocket=null;
        try {
            serverSocket=new ServerSocket(4700);
            System.out.println("服务器启动成功");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("服务器启动失败");
        }
        Socket socket=null;
        try {
            socket=serverSocket.accept();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String line;
        try {
            DataInputStream is=new DataInputStream(socket.getInputStream());
            DataOutputStream os=new DataOutputStream(socket.getOutputStream());
            System.out.println("Client:"+is.readUTF());
            BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
            line=sin.readLine();
            os.writeUTF(line);
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
